package com.combining.d_factory.main;

import com.combining.d_factory.Goose;
import com.combining.d_factory.face.AbstractDuckFactory;
import com.combining.d_factory.face.Quackable;
import com.combining.d_factory.impl.CountingDuckFactory;
import com.combining.d_factory.impl.GooseAdapter;
import com.combining.d_factory.impl.QuackCounter;

/**
 * 我们需要质量控制来确保鸭子一定是被包装起来的，我们要建造一个工厂，创建装饰过的鸭子。此工厂应该生产各种不同类型的鸭子的产品家族，所以用抽象工厂模式
 * 
 * @author dell
 * 
 */
public class DuckSimulator {
	public static void main(String[] args) {
		DuckSimulator simulator = new DuckSimulator();
		AbstractDuckFactory duckFactory = new CountingDuckFactory();

		simulator.simulate(duckFactory);
	}

	void simulate(AbstractDuckFactory duckFactory) {
		Quackable mallardDuck = duckFactory.createMallardDuck();
		Quackable redheadDuck = duckFactory.createRedheadDuck();
		Quackable duckCall = duckFactory.createDuckCall();
		Quackable rubberDuck = duckFactory.createRubberDuck();
		Quackable gooseDuck = new GooseAdapter(new Goose());

		System.out.println("\n鸭子模拟器，和鹅适配器，和装饰者，和工厂：");

		simulate(mallardDuck);
		simulate(redheadDuck);
		simulate(duckCall);
		simulate(rubberDuck);
		simulate(gooseDuck);

		System.out.println("鸭子共叫了" + QuackCounter.getQuacks() + "次");
	}

	void simulate(Quackable duck) {
		duck.quack();
	}
}
